package com.southwind.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.southwind.entity.TbAssertOrg;

import com.southwind.form.SearchForm;
import com.southwind.mapper.TbAssertOrgMapper;
import com.southwind.service.TbAssertOrgService;
import com.southwind.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fjh
 * @since 2024-01-09
 */
@Service
public class TbAssertOrgServiceImpl extends ServiceImpl<TbAssertOrgMapper, TbAssertOrg> implements TbAssertOrgService {
@Autowired
private TbAssertOrgMapper tbAssertOrgMapper;
    @Override
    public PageVO list(Integer page, Integer size) {
        Page<TbAssertOrg> tbAssertOrgPage = new Page<>(page, size);
        Page<TbAssertOrg> resultPage = this.tbAssertOrgMapper.selectPage(tbAssertOrgPage, null);
        PageVO pageVO = new PageVO();
        pageVO.setTotal(resultPage.getTotal());
        pageVO.setData(resultPage.getRecords());
        return pageVO;
    }

    @Override
    public PageVO search(SearchForm searchForm) {
//        模糊查询+分页
        Page<TbAssertOrg> tbAssetOrgPage = new Page<>(searchForm.getPage(), searchForm.getSize());
        Page<TbAssertOrg> resultPage = null;
        if(searchForm.getValue().equals("")){
            resultPage = this.tbAssertOrgMapper.selectPage(tbAssetOrgPage, null);
        } else {
            QueryWrapper<TbAssertOrg> queryWrapper = new QueryWrapper<>();
            queryWrapper.like(searchForm.getKey(), searchForm.getValue());
            resultPage = this.tbAssertOrgMapper.selectPage(tbAssetOrgPage,queryWrapper);
        }
        PageVO pageVO = new PageVO();
        pageVO.setTotal(resultPage.getTotal());
        pageVO.setData(resultPage.getRecords());
        return pageVO;
    }
}
